<template>
  <el-dialog
    :title="'订单详情'"
    :visible.sync="orderInfo"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="700px"
    center>
    <div class="orderinfo-div">
      <div class="orderinfo-title">基本信息</div>
      <span>联系人： {{orderInfoData.ContactName}} </span>
      <span style="width:60%" :title="orderInfoData.PhoneAttribution">
        联系电话： {{orderInfoData.ContactPhone}}({{orderInfoData.PhoneAttribution}})
        <a @click="SendSMS" href="javascript:void(0);">发送短信</a>
      </span>
      <span>销售员： {{getSaleMan(orderInfoData.SalesmanId)}}</span>
      <span>支付类型： {{orderInfoData.PaymentModeName}}</span>
      <span>渠道来源： {{orderInfoData.FromChannelName}}</span>
      <span v-if="!!orderInfoData.TravelAgencyName">渠道商： {{orderInfoData.TravelAgencyName}}</span>
    </div>
    <div class="orderinfo-div">
      <div class="orderinfo-title">
        预定信息<span style="font-size:14px">（订单号：{{orderInfoData.OrderSerialid}}）</span>
      </div>
      <template  v-for="m in orderInfoData.HotelOrders">
        <span>入住：{{m.CheckInDate.split('T')[0]}}</span>
        <span>离店：{{m.CheckOutDate.split('T')[0]}}</span>
        <span>共{{getAlldate(m.CheckInDate,m.CheckOutDate).length-1}}晚</span>
        <span>房型：{{m.RoomCategoryName}}<i class="type" :class="{'room-book':m.Status===0,'room-in':m.Status===1}">{{orderTypeList[m.Status]}}</i></span>
        <span>房间号：{{m.RoomNo}}</span>
        <span>价格：<b>{{m.AllAmount}}元</b></span>
        <p v-for="n in m.Roomers">
          <span>入住人姓名： {{n.Name}}</span>
          <span>入住人{{cerList[n.CertType]}}：{{n.CertNo}}</span>
        </p>
      </template>
      <p v-for="m in orderInfoData.SingleProductOrders">
        <span>商品：{{m.ProductName}}（{{m.UnitPrice}}/{{m.Unit}}）</span>
        <span>数量：{{m.Quantity}}{{m.Unit}}</span>
        <span>价格：<b>{{m.AllAmount}}元</b></span>
      </p>
    </div>
    <div class="orderinfo-div">
      <div class="orderinfo-title">
        收银信息
      </div>
      <span>订单总额: <b>¥{{orderInfoData.AllAmount}}</b></span>
      <span>已收款：<b>¥{{orderInfoData.PaidAmount}}</b></span>
      <span>需补交：<b>¥{{orderInfoData.RestAmount}}</b></span>
      <span @click="getpriceData" style="cursor:pointer;color: #399be6;margin-left:10px;float: right;text-align:right">财务明细</span>
      <div style="padding:10px 20px 0px 0px;float: left;">
        <el-dropdown trigger="hover" placement="top" @command="addPriceInfo">
          <span class="el-dropdown-link">添加款项</span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item :command="{type:1,name:'收款'}">收款</el-dropdown-item>
            <el-dropdown-item :command="{type:2,name:'商品'}">商品</el-dropdown-item>
            <el-dropdown-item :command="{type:3,name:'收押金'}">收押金</el-dropdown-item>
            <el-dropdown-item :command="{type:4,name:'退款'}">退款</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <el-table
        :data="tableData"
        style="width: 95%;margin:5px auto;max-height: 200px;overflow: auto;"
        v-show="tableShow">
        <el-table-column
          prop="CashierItem"
          label="项目">
          <template slot-scope="scope">
            {{CashierItem[scope.row.CashierItem]}}
          </template>
        </el-table-column>
        </el-table-column>
        <el-table-column
          prop="Amount"
          label="收款">
        </el-table-column>
        <el-table-column
          label="支付方式"
          prop="CashierChannelDes">
        </el-table-column>
        <el-table-column
          prop="Remark"
          label="财务备注">
        </el-table-column>
        <el-table-column
          prop="OperatorTime"
          label="操作时间"
          width="92">
          <template slot-scope="scope">
            <template v-if="!!scope.row.OperatorTime">{{scope.row.OperatorTime.split('T')[0]}}</template>
          </template>
        </el-table-column>
        <el-table-column
          prop="OperatorName"
          label="操作人">
        </el-table-column>
        <el-table-column
          label="操作"
          class="delete-td">
          <template slot-scope="scope">
            <span @click="deletePriceInfo(scope.row)" v-if="scope.row.IsValid" style="color:rgb(57, 155, 230);cursor:pointer;">删除</span>
            <span v-else style="color:red">已删除</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="orderinfo-div">
      <div class="orderinfo-title">
        备注
      </div>
      <p><span>{{orderInfoData.Remark}}</span></p>
    </div>
    <span slot="footer" class="dialog-footer">
      <template v-if="orderInfoData.OrderStatus!==5">
        <el-button type="warning" size="mini" round @click="editOrder" data-auth="store_order_modify">修改订单</el-button>
        <el-button type="warning" size="mini" round @click="roominShowBtn" data-auth="store_order_checkin" v-if="orderInfoData.OrderStatus!==1">办理入住</el-button>
        <el-button type="warning" size="mini" round @click="printOrder(orderInfoData.OrderSerialid)" data-auth="store_order_print" v-if="orderInfoData.OrderStatus===1||orderInfoData.OrderStatus===2">打印入住凭证</el-button>
        <el-button type="warning" size="mini" round @click="roomoutShowBtn" data-auth="store_order_checkout" v-if="orderInfoData.OrderStatus!==0">办理退房</el-button>
        <el-button type="warning" size="mini" round @click="deleteOrderShowBtn" data-auth="store_order_cancle" v-if="orderInfoData.OrderStatus===0">取消订单</el-button>
        <el-button type="warning" size="mini" round data-auth="store_order_log" @click.stop="() => {formData.orderSerialid=orderInfoData.OrderSerialid;$refs.tim.toggleDiolag()}">订单日志</el-button>
      </template>
    </span>
  </el-dialog>
</template>
<script>
  export default {
    props:['formData','title'],
    data() {
      return {
        showInfo:false,
        timeList:[],
        orderInfoData:{},
      }
    },
    created() {
    },
    methods: {
      notice(){
        this.timeList=[];
        this.orderSerialid=id;
        this.$ajax.getorderdetail({OrderSerialid:this.orderSerialid}).then(res=>{
          if(res.Success){
            this.orderInfoData=res.Data;
            this.orderInfo=true;
            this.tableShow=false;
            if(this.roomoutShow||this.roominShow){

            }else{
              this.roomoutShow=false;
              this.roominShow=false;
            }
          }
        })
      },
      editOrder(){
        this.dialogData=[];
        this.ruleForm={};
        this.ProductList=[];
        this.ruleForm=_.cloneDeep(this.orderInfoData);
        this.ruleForm.RoomList=this.ruleForm.HotelOrders;
        this.ProductList=this.ruleForm.SingleProductOrders;
        _.map(this.ruleForm.RoomList,val=>{
          this.dialogData.push({
            roomName:val.RoomCategoryName,
            "PolicyName": val.RoomCategoryName,
            "PolicyId": val.RoomCategoryPolicyId,
            "HotelId": JSON.parse(sessionStorage.getItem('nowmenu')).Id,
            "HotelName": JSON.parse(sessionStorage.getItem('nowmenu')).name,
            "roomId": val.RoomCategoryId,
            "Id":val.RoomId,
            "HotelOrderId":val.Id,
            "roomNum": val.RoomNo,
            "startDate": val.CheckInDate,
            "endDate": val.CheckOutDate,
            "Days": this.getAlldate(val.CheckInDate,val.CheckOutDate).length-1,
            "AllAmount": val.AllAmount,
            "PolicyPriceAmount": val.PolicyPriceAmount,
            Status:val.Status,
            "Roomers": val.Roomers
          })
        })
        delete this.ruleForm.HotelOrders;
        delete this.ruleForm.SingleProductOrders;
        this.dialogTitle='修改订单';
        this.OrderAction=0;
        _.map(this.ProductList,(val,index)=>{
          this.$ajax.GetSingleProductByType({type:val.ProductType,hotelId:JSON.parse(sessionStorage.getItem('nowmenu')).Id}).then(res=>{
            if(res.Success){
              this.$set(this.ProductList[index],'ProductNameList',res.Data)
            }
          })
        })
        this.getAllAmount();
        _.map(this.dialogData,(val,index)=>{
          let data={
            HotelOrderId:val.HotelOrderId||0,
            CheckInTime:val.startDate,
            CheckOutTime:val.endDate,
            RoomCategoryId:val.roomId,
            HotelId:val.HotelId
          }
          val.roomData=[];
          this.$ajax.GetAvailableRooms(data).then(res=>{
            if(res.Success){
              val.roomData=res.Data;
              this.$set(this.dialogData,index,val)
            }
          })
          return val;
        })
        this.$nextTick(()=>{
          this.showAddRoom();
        })
      },
      toggleDiolag(){
        this.showInfo=!this.showInfo;
        if(this.showInfo){
          this.notice();
        }
      }
    }
  }

</script>
<style lang="scss">
.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden}
.info-dialog .el-dialog__body{
  padding:0 20px;
}
.time-main{
  overflow: hidden;
}
.time-left{
  width: 15%;
  text-align: right;
  margin-top: 20px;
  padding-right: 20px;
  box-sizing: border-box;
  z-index: 2;
}
.time-first:before{
  content: '';
  height: 15px;
  position: absolute;
  right:-1px;
  background: #fff;
  width: 1px;
}
.time-left,.time-right{
  float: left;
  position: relative;
  line-height: 40px;
}
.time-right{
  width: 80%;
  padding: 0 20px;
  margin-top: 20px;
  &:before{
    content: '';
    height: 150%;
    position: absolute;
    left: 0px;
    background: #409eff;
    width: 1px;
  }
  z-index: 1;
  box-shadow: 3px 3px 3px 0px #409eff5e;
  p:first-child{
    color:#000;
    span{
      float: right;
    }
  }
}
.title-day{
  overflow: hidden;
  color: #ef7c29;
  font-size: 16px;
  font-weight: bold;
}
.title-day .time-left:after{
  border: solid transparent;
  content: ' ';
  height: 20px;
  right: -12px;
  top:9px;
  position: absolute;
  width: 20px;
  border-radius: 20px;
  background: #fff;
  border: 2px solid #ef7c29;
}
.title-time .time-left:after{
  content: ' ';
  height: 10px;
  right: -6px;
  top: 14px;
  position: absolute;
  width: 10px;
  border-radius: 10px;
  background: #ef7c29;
  border: 1px solid #ef7c29;
}
.title-time .bg-blue.time-left:after{
  background: #409EFF;
  border: 1px solid #409EFF;
}
.title-end{
  width: 15%;
  left:1px;
  text-align: right;
  border-right:1px solid #409EFF;
  padding-right: 20px;
  margin-right: 20px;
  box-sizing: border-box;
  height: 30px;
  position: relative;
}

.title-end:after, .title-end:before {
  border: solid transparent;
  content: ' ';
  height: 0;
  right: -11px;
  position: absolute;
  width: 0;
}
.title-end:after {
  border-width: 10px;
  border-top-color: #409EFF;
  top: 20px;
}
</style>
